Skip to content

Fix: Use /tmp for SQLite environments on Vercel serverless#1206

Merged
os-zhuang merged 1 commit intomainfrom
claude/fix-vercel-environment-creation
Apr 21, 2026
Merged

Fix: Use /tmp for SQLite environments on Vercel serverless#1206
os-zhuang merged 1 commit intomainfrom
claude/fix-vercel-environment-creation

Conversation

@Claude
Copy link
Copy Markdown
Contributor

@Claude Claude AI commented Apr 21, 2026

Environment creation on Vercel was silently failing: POST returned 202 Accepted but subsequent GET returned 404. The provisioning process failed because SQLite adapters tried writing to read-only filesystem paths.

Changes

  • Serverless environment detection in createDefaultEnvironmentAdapters():

    • Checks VERCEL=1, AWS_LAMBDA_FUNCTION_NAME, or FUNCTION_NAME
    • Routes SQLite files to /tmp/.objectstack/data/environments/ in serverless contexts
    • Preserves .objectstack/data/environments/ for local development
  • Applied to both adapters:

    • sqlite driver (direct)
    • turso driver (fallback when no cloud credentials configured)

Implementation

const isServerless = env.VERCEL === '1' || env.AWS_LAMBDA_FUNCTION_NAME || env.FUNCTION_NAME;
const sqliteBaseDir = isServerless
  ? '/tmp/.objectstack/data/environments'
  : '.objectstack/data/environments';

adapters.push(new LocalSQLiteEnvironmentDatabaseAdapter(sqliteBaseDir));
// ...
adapters.push(new LocalSQLiteEnvironmentDatabaseAdapter(sqliteBaseDir, 'turso'));

Note

Production deployments should use Turso cloud credentials (TURSO_ORG_NAME + TURSO_API_TOKEN) for persistence. SQLite in /tmp is ephemeral across cold starts.

Fixes environment creation failure on Vercel deployment where POST succeeds but GET returns 404.

**Root Cause:**
- LocalSQLiteEnvironmentDatabaseAdapter was trying to write to `.objectstack/data/environments/`
- Vercel serverless functions have read-only filesystem except for `/tmp`
- Environment provisioning failed silently when trying to create database files
- POST returned 202 Accepted, but async provisioning failed
- Subsequent GET requests returned 404 because environment was stuck in "failed" state

**Solution:**
- Detect serverless environments (VERCEL=1, AWS_LAMBDA_FUNCTION_NAME, FUNCTION_NAME)
- Use `/tmp/.objectstack/data/environments/` in serverless, `.objectstack/data/environments/` in local dev
- Both `sqlite` and `turso` (fallback) adapters now use the serverless-aware path

**Testing:**
- Environment creation will now succeed on Vercel
- Local development unaffected (still uses relative path)
- AWS Lambda and similar platforms also supported

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>

Co-authored-by: os-zhuang <277994282+os-zhuang@users.noreply.github.com>
@vercel
Copy link
Copy Markdown

vercel Bot commented Apr 21, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
objectstack-demo Ready Ready Preview, Comment Apr 21, 2026 2:34pm
spec Ready Ready Preview, Comment Apr 21, 2026 2:34pm

Request Review

@os-zhuang os-zhuang marked this pull request as ready for review April 21, 2026 15:55
@os-zhuang os-zhuang merged commit a72e12d into main Apr 21, 2026
13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants